﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech.Synthesis;

namespace DuBaiCoffee2.Model
{
   

    public class VoiceSwitcher
    {
        private SpeechSynthesizer synthesizer;

        public VoiceSwitcher()
        {
            synthesizer = new SpeechSynthesizer();
        }

        public void SwitchVoice(string name)
        {
            // 获取所有已安装的语音
            var voices = synthesizer.GetInstalledVoices();

            // 查找指定名称的语音
            foreach (var voice in voices)
            {
                if (voice.VoiceInfo.Name == name)
                {
                    // 切换到指定的语音
                    synthesizer.SelectVoice(voice.VoiceInfo.Name);
                    break;
                }
            }
        }

        public void Speak(string text)
        {
            synthesizer.SpeakAsync(text);
        }
    }
}
